using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using FireStarter.Base;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using FireStarterModeller.Test.BO.Fakes;
using Habanero.Base;
using Habanero.Base.Exceptions;
using Habanero.BO;
using Habanero.Util;
using NUnit.Framework;
using Rhino.Mocks;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DMRelationship objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DMRelationship.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDMRelationship
    {
        [SetUp]
        public override void SetupTest()
        {
            //Runs every time that any testmethod is executed
            base.SetupTest();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            _ignoreList.Add("Test_SaveDMRelationship", "Overridden");
            base.SetupFixture();
        }

        [TearDown]
        public override void TearDownTest()
        {
            //runs every time any testmethod is complete
            base.TearDownTest();
        }

        #region Overridden Tests

        [Test]  // Ensures that a class can be successfully saved
        public void Test_SaveDMRelationship_Override()
        {
            CheckIfTestShouldBeIgnored();
            //---------------Set up test pack-------------------
            DMRelationship dMRelationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();

            //---------------Assert Precondition----------------
            Assert.IsTrue(dMRelationship.Status.IsNew);
            BusinessObjectCollection<DMRelationship> col = new BusinessObjectCollection<DMRelationship>();
            col.LoadAll();
            Assert.AreEqual(0, col.Count);

            //---------------Execute Test ----------------------
            dMRelationship.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(dMRelationship.Status.IsNew);
            col.LoadAll();
            Assert.AreEqual(2, col.Count);
        }

        #endregion

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            //---------------Assert Precondition----------------
            Assert.IsFalse(String.IsNullOrEmpty(dmRelationship.RelationshipName), "RelationshipName Should not be null");
            //---------------Execute Test ----------------------
            string actualToString = dmRelationship.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmRelationship.RelationshipName, actualToString);
        }
        [Test]
        public void Test_ToString_RelationshipNameNull()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            dmRelationship.RelationshipName = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(String.IsNullOrEmpty(dmRelationship.RelationshipName), "RelationshipName Should be null");
            //---------------Execute Test ----------------------
            string actualToString = dmRelationship.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmRelationship.RelationshipID.ToString(), actualToString);
        }
        [Test]
        public void Test_ToString_RelationshipNameNull_RelationshipIDNull()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            dmRelationship.RelationshipName = null;
            dmRelationship.RelationshipID = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(String.IsNullOrEmpty(dmRelationship.RelationshipName), "RelationshipName Should be null");
            Assert.IsNull(dmRelationship.RelationshipID);
            //---------------Execute Test ----------------------
            string actualToString = dmRelationship.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("-unnamed Relationship-", actualToString);
        }

        [Test]
        public void Test_InsertNewRelationshipInfo_Invalid()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();

            //---------------Assert Precondition----------------
            Assert.IsTrue(dmRelationship.Status.IsNew);

            //---------------Execute Test ----------------------
            try
            {
            dmRelationship.Save();
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (BusObjectInAnInvalidStateException ex)
            {
                StringAssert.Contains("must have at least one Property", ex.Message);
            }
            Assert.IsTrue(dmRelationship.Status.IsNew);
        }

        [Test]
        public void Test_DeleteRelationshipInfo()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = TestUtilsShared.CreateSavedRelationshipInfo();

            //---------------Assert Precondition----------------
            Assert.IsFalse(dmRelationship.Status.IsNew);
            string message;
            Assert.IsTrue(dmRelationship.IsDeletable(out message));

            //---------------Execute Test ----------------------
            dmRelationship.MarkForDelete();
            dmRelationship.Save();

            //---------------Test Result -----------------------  
            Assert.IsTrue(dmRelationship.Status.IsNew);
            Assert.IsTrue(dmRelationship.Status.IsDeleted);
        }

        [Test]
        public void Test_UpdateRelationshipInfo()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = TestUtilsShared.CreateSavedRelationshipInfo();

            //---------------Assert Precondition----------------
            Assert.IsFalse(dmRelationship.Status.IsNew);
            string message;
            Assert.IsTrue(dmRelationship.IsEditable(out message));

            //---------------Execute Test ----------------------
            TestUtilsShared.UpdateRelationshipInfoWithValidData(dmRelationship);

            //---------------Test Result -----------------------
            Assert.IsFalse(dmRelationship.Status.IsNew);
        }

        [Test]
        public void Test_RelatedClassIDProp_IsEditable_ShouldBeTrue_WhenNotGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship();
            //--------------- Test Preconditions ----------------
            Assert.IsFalse(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["ClassID"];
            //--------------- Test Result -----------------------
            string message = "";
            Assert.AreEqual("", message);
            Assert.IsTrue(prop.IsEditable(out message));
        }

        [Test]
        public void Test_RelatedClassIDProp_IsEditable_ShouldBeFalse_WhenGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship {Generated = true};
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["ClassID"];
            //--------------- Test Result -----------------------
            string message;
            Assert.IsFalse(prop.IsEditable(out message));
        }

        [Test]
        public void Test_RelationshipNameProp_IsEditable_ShouldBeTrue_WhenNotGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship();
            //--------------- Test Preconditions ----------------
            Assert.IsFalse(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["RelationshipName"];
            //--------------- Test Result -----------------------
            string message = "";
            Assert.AreEqual("", message);
            Assert.IsTrue(prop.IsEditable(out message));
        }

        [Test]
        public void Test_RelationshipNameProp_IsEditable_ShouldBeFalse_WhenGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship {Generated = true};
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["RelationshipName"];
            //--------------- Test Result -----------------------
            string message;
            Assert.IsFalse(prop.IsEditable(out message));
        }

        [Test]
        public void Test_CardinalityProp_IsEditable_ShouldBeTrue_WhenNotGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship();
            //--------------- Test Preconditions ----------------
            Assert.IsFalse(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["Cardinality"];
            //--------------- Test Result -----------------------
            string message = "";
            Assert.AreEqual("", message);
            Assert.IsTrue(prop.IsEditable(out message));
        }

        [Test]
        public void Test_CardinalityProp_IsEditable_ShouldBeFalse_WhenGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship {Generated = true};
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["Cardinality"];
            //--------------- Test Result -----------------------
            string message;
            Assert.IsFalse(prop.IsEditable(out message));
        }

        [Test]
        public void Test_RelationshipTypeProp_IsEditable_ShouldBeTrue_WhenNotGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship();
            //--------------- Test Preconditions ----------------
            Assert.IsFalse(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["RelationshipType"];
            //--------------- Test Result -----------------------
            string message = "";
            Assert.AreEqual("", message);
            Assert.IsTrue(prop.IsEditable(out message));
        }

        [Test]
        public void Test_RelationshipTypeProp_IsEditable_ShouldBeFalse_WhenGenerated()
        {
            //--------------- Set up test pack ------------------
            DMRelationship relationship = new DMRelationship {Generated = true};
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(relationship.Generated.GetValueOrDefault());
            //--------------- Execute Test ----------------------
            IBOProp prop = relationship.Props["RelationshipType"];
            //--------------- Test Result -----------------------
            string message;
            Assert.IsFalse(prop.IsEditable(out message));
        }

        [Test]
        public void Test_HasOwnerProperty_WhenHasProperty_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMRelationshipProperty relationshipProperty = relationship.RelationshipProperties.CreateBusinessObject();
            DMProperty property = relationship.OwnerClass.Properties.CreateBusinessObject();
            relationshipProperty.OwnerProperty = property;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasOwnerProperty = relationship.HasOwnerProperty(property);
            //---------------Test Result -----------------------
            Assert.IsTrue(hasOwnerProperty);
        }
        [Test]
        public void Test_HasOwnerProperty_WhenNotHasProperty_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMRelationshipProperty relationshipProperty = relationship.RelationshipProperties.CreateBusinessObject();
            DMProperty property = relationship.OwnerClass.Properties.CreateBusinessObject();
            relationshipProperty.OwnerProperty = property;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasOwnerProperty = relationship.HasOwnerProperty(relationship.OwnerClass.Properties.CreateBusinessObject());
            //---------------Test Result -----------------------
            Assert.IsFalse(hasOwnerProperty);

        }
        [Test]
        public void Test_HasRelatedProperty_WhenHasProperty_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMRelationshipProperty relationshipProperty = relationship.RelationshipProperties.CreateBusinessObject();
            DMProperty property = relationship.RelatedClass.Properties.CreateBusinessObject();
            relationshipProperty.RelatedProperty = property;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasRelatedProperty = relationship.HasRelatedProperty(property);
            //---------------Test Result -----------------------
            Assert.IsTrue(hasRelatedProperty);
        }
        [Test]
        public void Test_HasRelatedProperty_WhenNotMatchesProperty_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMRelationshipProperty relationshipProperty = relationship.RelationshipProperties.CreateBusinessObject();

            DMProperty property = relationship.RelatedClass.Properties.CreateBusinessObject();

            relationshipProperty.RelatedProperty = property;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasRelatedProperty = relationship.HasRelatedProperty(relationship.RelatedClass.Properties.CreateBusinessObject());
            //---------------Test Result -----------------------
            Assert.IsFalse(hasRelatedProperty);

        }
        [Test]
        public void Test_HasRelatedProperty_WhenNotHasProperty_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMRelationshipProperty relationshipProperty = relationship.RelationshipProperties.CreateBusinessObject();

            relationshipProperty.RelatedPropertyName = GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasRelatedProperty = relationship.HasRelatedProperty(relationship.RelatedClass.Properties.CreateBusinessObject());
            //---------------Test Result -----------------------
            Assert.IsFalse(hasRelatedProperty);

        }

        [Test]
        public void Test_HasRelatedProperty_WhenNotHasPropertyButRelPropNameMatches_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMRelationshipProperty relationshipProperty = relationship.RelationshipProperties.CreateBusinessObject();

            relationshipProperty.RelatedPropertyName = GetRandomString();
            DMProperty prop = relationship.RelatedClass.Properties.CreateBusinessObject();
            prop.PropertyName = relationshipProperty.RelatedPropertyName;
            DMProperty property = relationship.RelatedClass.Properties.CreateBusinessObject();
            relationshipProperty.RelatedProperty = property;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool hasRelatedProperty = relationship.HasRelatedProperty(prop);
            //---------------Test Result -----------------------
            Assert.IsFalse(hasRelatedProperty);

        }


        [Test]
        public void Test_IsDeletable_ShouldReturnFalse_WhenGenerated()
        {
            //--------------- Set up test pack ------------------
            string message;
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            relationship.Generated = true;
            //--------------- Test Preconditions ----------------
            Assert.IsTrue(relationship.Generated.Value);
            //--------------- Execute Test ----------------------
            bool isDeletable = relationship.IsDeletable(out message);
            //----------Test Result -----------------------
            Assert.IsFalse(isDeletable);
            StringAssert.Contains
                ("The relationship '" + relationship.ToString() + "' cannot be deleted as it has already been exported",
                 message);
        }

        [Test]
        public void Test_Save_ShouldDeleteDMSortOrder_WhenHasNoSortProperties()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMSortOrder dmSortOrder = new DMSortOrder();
            relationship.DMSortOrder = dmSortOrder;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship.DMSortOrder);
            Assert.AreEqual(0, relationship.DMSortOrder.DMSortProperties.Count);
            Assert.IsTrue(dmSortOrder.Status.IsNew);
            Assert.IsFalse(dmSortOrder.Status.IsDeleted);
            //---------------Execute Test ----------------------
            relationship.Save();
            //---------------Test Result -----------------------
            Assert.IsTrue(dmSortOrder.Status.IsNew);
            Assert.IsTrue(dmSortOrder.Status.IsDeleted);
            Assert.IsTrue(dmSortOrder.Status.IsDirty);
            Assert.IsNull(relationship.DMSortOrder);
        }

        [Test]
        public void Test_Save_ShouldNotDeleteDMSortOrder_WhenHasSortProperties()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedValidDMRelationship();
            DMSortOrder dmSortOrder = new DMSortOrder();
            TestUtilsDMSortProperty.CreateUnsavedValidDMSortProperty(dmSortOrder);
            relationship.DMSortOrder = dmSortOrder;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship.DMSortOrder);
            Assert.AreEqual(1, relationship.DMSortOrder.DMSortProperties.Count);
            Assert.IsTrue(dmSortOrder.Status.IsNew);
            Assert.IsFalse(dmSortOrder.Status.IsDeleted);
            //---------------Execute Test ----------------------
            relationship.Save();
            //---------------Test Result -----------------------
            Assert.IsFalse(dmSortOrder.Status.IsNew);
            Assert.IsFalse(dmSortOrder.Status.IsDeleted);
            Assert.IsFalse(dmSortOrder.Status.IsDirty);
            Assert.AreSame(dmSortOrder, relationship.DMSortOrder);
        }

        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenBothHave_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(ownerClass);
            DMClass relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(relatedClass);

            DMRelationship relationship = CreatRelationship(ownerClass, relatedClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(relatedClass, relationship.ReverseRelationship.ClassDM);
            Assert.AreEqual(1, ownerClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(1, relatedClass.ObjectIdentity.Properties.Count);
            Assert.IsTrue(ownerClass.IsSinglePropObjectID);
            Assert.IsTrue(relatedClass.IsSinglePropObjectID);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsTrue(hasSinglePropIDs);
        }
        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenRelatedClassnotSet_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(ownerClass);
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedDefaultDMRelationship();
            relationship.ClassDM = ownerClass;
            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.ReverseRelationship.ClassDM);
            Assert.AreEqual(1, ownerClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSinglePropIDs);
        }

        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenOwnerClassObjectIDNull_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            DMClass relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(relatedClass);
            DMRelationship relationship = CreatRelationship(ownerClass, relatedClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(relatedClass, relationship.ReverseRelationship.ClassDM);
            Assert.IsNull(ownerClass.ObjectIdentity);
            Assert.AreEqual(1, relatedClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSinglePropIDs);
        }
        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenOwnerClassDoesNot_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            ownerClass.CreateObjectIdentity();
            DMClass relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(relatedClass);
            DMRelationship relationship = CreatRelationship(ownerClass, relatedClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(relatedClass, relationship.ReverseRelationship.ClassDM);
            Assert.AreEqual(0, ownerClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(1, relatedClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSinglePropIDs);
        }
        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenOwnerClassObjectIDHasTwoProps_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            DMObjectIdentity identity = ownerClass.CreateObjectIdentity();
            DMProperty dmProperty1 = TestUtilsDMProperty.CreateUnsavedValidDMProperty(ownerClass);
            DMProperty dmProperty2 = TestUtilsDMProperty.CreateUnsavedValidDMProperty(ownerClass);
            identity.Properties.Add(dmProperty1);
            identity.Properties.Add(dmProperty2);
            DMClass relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(relatedClass);
            DMRelationship relationship = CreatRelationship(ownerClass, relatedClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(relatedClass, relationship.ReverseRelationship.ClassDM);
            Assert.AreEqual(2, ownerClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(1, relatedClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSinglePropIDs);
        }

        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenRelatedClassObjectIDNull_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(ownerClass);
            DMClass relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();

            DMRelationship relationship = CreatRelationship(ownerClass, relatedClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(relatedClass, relationship.ReverseRelationship.ClassDM);
            Assert.IsNull(relatedClass.ObjectIdentity);
            Assert.AreEqual(1, ownerClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSinglePropIDs);
        }
        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenRelatedClassDoesNot_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            TestUtilsShared.CreateSavedObjectIdentityInfo(ownerClass);
            DMClass relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            relatedClass.CreateObjectIdentity();
            DMRelationship relationship = CreatRelationship(ownerClass, relatedClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(relatedClass, relationship.ReverseRelationship.ClassDM);
            Assert.AreEqual(1, ownerClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(0, relatedClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSinglePropIDs);
        }

        [Test]
        public void Test_BothClassesHaveSinglePropIDs_WhenRelatedClassObjectIDHasTwoProps_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass ownerClass = TestUtilsDMClass.CreateUnsavedValidDMClass();

            TestUtilsShared.CreateSavedObjectIdentityInfo(ownerClass);
            DMClass relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            DMObjectIdentity identity = relatedClass.CreateObjectIdentity();
            AddTwoPropsToObjectID(relatedClass, identity);
            DMRelationship relationship = CreatRelationship(ownerClass, relatedClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(relatedClass, relationship.ReverseRelationship.ClassDM);
            Assert.AreEqual(1, ownerClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(2, relatedClass.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            bool hasSinglePropIDs = relationship.BothClassesHaveSinglePropIDs;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasSinglePropIDs);
        }

        [Test]
        public void Test_DMRelationshipDeleteActionRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMRelationshipDeleteActionRule>(rules);
        }

        [Test]
        public void Test_DMRelationshipMustHavePropertyRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
           TestUtilsShared.AssertHasRuleOfType<DMRelationshipMustHaveProperty>(rules);
        }

        [Test]
        public void Test_DMRelationshipOneDirectionMustBeDoNothing_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMRelationshipOneDirectionMustBeDoNothing>(rules);
        }

        [Test]
        public void Test_DMRelationshipPropKeyRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMRelationshipOnetoOneAndManytoOnePropKeyRule>(rules);
        }

        [Test]
        public void Test_DMRelationshipSingleToSingleAKRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMRelationshipSingleToSingleAKRule>(rules);
        }

        [Test]
        public void Test_DMSortOrderPropMustBeOnClassRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMSortOrderPropMustBeOnRelatedClassRule>(rules);
        }

        [Test]
        public void Test_DMRelationshipSingleToMultiplePropKeyRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMRelationshipSingleToMultipleCannotBePKorUC>(rules);
        }

        [Test]
        public void Test_DMRelationshipOneDirectionMustBeAssociation_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMRelationshipOneToOneOneSideMustBeAssociation>(rules);
        }

        [Test]
        public void Test_DMRelationshipManyToOneMustBeAssociation_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(dmRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMRelationshipManyToOneMustBeAssociation>(rules);
        }

        [Test]
        public void Test_HasAllPKProps_False_WhenNoObjectIdentity()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMRelationship dmRelationship = dmClass.OwnerRelationships.CreateBusinessObject();

            //---------------Assert Precondition----------------
            Assert.IsNull(dmClass.ObjectIdentity);
            //---------------Execute Test ----------------------
            bool hasAllPkProps = dmRelationship.HasAllPkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllPkProps);
        }

        [Test]
        public void Test_HasAllPKProps_True_WhenAllPKProps()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMObjectIdentity objectIdentity = dmClass.CreateObjectIdentity();
            AddTwoPropsToObjectID(dmClass, objectIdentity);
            DMRelationship dmRelationship = dmClass.OwnerRelationships.CreateBusinessObject();
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[0]);
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[1]);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(2, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllPkProps = dmRelationship.HasAllPkProps();
            //---------------Test Result -----------------------
            Assert.IsTrue(hasAllPkProps);
        }

        [Test]
        public void Test_HasAllPKProps_False_WhenDoesNotHaveAllPKProps()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMObjectIdentity objectIdentity = dmClass.CreateObjectIdentity();
            AddTwoPropsToObjectID(dmClass, objectIdentity);
            DMProperty property = dmClass.Properties.CreateBusinessObject();
            objectIdentity.Properties.Add(property);
            DMRelationship dmRelationship = dmClass.OwnerRelationships.CreateBusinessObject();
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[0]);
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[1]);

            //---------------Assert Precondition----------------
            Assert.AreEqual(3, dmClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(2, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllPkProps = dmRelationship.HasAllPkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllPkProps);
        }

        [Test]
        public void Test_HasAllPKProps_False_WhenDoesNotHaveAllPKProps_DiffNoPropsAsPK()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMObjectIdentity objectIdentity = dmClass.CreateObjectIdentity();
            AddTwoPropsToObjectID(dmClass, objectIdentity);
            DMProperty property = dmClass.Properties.CreateBusinessObject();
            DMRelationship dmRelationship = dmClass.OwnerRelationships.CreateBusinessObject();
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[0]);
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[1]);
            AddRelationshipProperty(dmRelationship, property);

            //---------------Assert Precondition----------------
            Assert.AreEqual(2, dmClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(3, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllPkProps = dmRelationship.HasAllPkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllPkProps);
        }

        [Test]
        public void Test_HasAllPKProps_False_WhenDoesNotHaveAllPKProps_SameNoPropsAsPK()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMObjectIdentity objectIdentity = dmClass.CreateObjectIdentity();
            AddTwoPropsToObjectID(dmClass, objectIdentity);
            DMProperty idProperty = dmClass.Properties.CreateBusinessObject();
            objectIdentity.Properties.Add(idProperty);
            DMProperty property = dmClass.Properties.CreateBusinessObject();
            DMRelationship dmRelationship = dmClass.OwnerRelationships.CreateBusinessObject();
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[0]);
            AddRelationshipProperty(dmRelationship, objectIdentity.Properties[1]);
            AddRelationshipProperty(dmRelationship, property);

            //---------------Assert Precondition----------------
            Assert.AreEqual(3, dmClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(3, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllPkProps = dmRelationship.HasAllPkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllPkProps);
        }

        [Test]
        public void Test_HasAllAKProps_True_WhenAllAKProps()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = CreateClassWithAkAndRelationship();
            DMUniqueConstraint uniqueConstraint = dmClass.UniqueConstraints[0];
            DMRelationship dmRelationship = dmClass.OwnerRelationships[0];
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, uniqueConstraint.Properties.Count);
            Assert.AreEqual(1, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllAkProps = dmRelationship.HasAllAkProps();
            //---------------Test Result -----------------------
            Assert.IsTrue(hasAllAkProps);
        }

        [Test]
        public void Test_HasAllAKProps_False_WhenDoesNotHaveAllAKProps_DiffNoPropsAsAK()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = CreateClassWithAkAndRelationship();
            DMProperty dmProperty = dmClass.Properties.CreateBusinessObject();
            DMUniqueConstraint uniqueConstraint = dmClass.UniqueConstraints[0];
            DMRelationship dmRelationship = dmClass.OwnerRelationships[0];
            DMRelationshipProperty relationshipProperty = dmRelationship.RelationshipProperties.CreateBusinessObject();
            relationshipProperty.Property = dmProperty;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, uniqueConstraint.Properties.Count);
            Assert.AreEqual(2, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllAkProps = dmRelationship.HasAllAkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllAkProps);
        }

        [Test]
        public void Test_HasAllAKProps_False_WhenDoesNotHaveAllAKProps()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = CreateClassWithAkAndRelationship();
            DMProperty dmProperty = dmClass.Properties.CreateBusinessObject();
            DMUniqueConstraint uniqueConstraint = dmClass.UniqueConstraints[0];
            uniqueConstraint.AddPropertyInfo(dmProperty);
            DMRelationship dmRelationship = dmClass.OwnerRelationships[0];
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, uniqueConstraint.Properties.Count);
            Assert.AreEqual(1, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllAkProps = dmRelationship.HasAllAkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllAkProps);
        }

        [Test]
        public void Test_HasAllAKProps_False_WhenDoesNotHaveAllAKProps_SameNoOfProps()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = CreateClassWithAkAndRelationship();
            DMProperty dmProperty1 = dmClass.Properties.CreateBusinessObject();
            DMProperty dmProperty2 = dmClass.Properties.CreateBusinessObject();
            DMUniqueConstraint uniqueConstraint = dmClass.UniqueConstraints[0];
            uniqueConstraint.AddPropertyInfo(dmProperty1);
            DMRelationship dmRelationship = dmClass.OwnerRelationships[0];
            DMRelationshipProperty relationshipProperty = dmRelationship.RelationshipProperties.CreateBusinessObject();
            relationshipProperty.Property = dmProperty2;
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, uniqueConstraint.Properties.Count);
            Assert.AreEqual(2, dmRelationship.RelationshipProperties.Count);
            Assert.AreSame(uniqueConstraint.UniqueConstraintProperties.First().Property, dmRelationship.RelationshipProperties.First().Property);
            Assert.AreNotSame(uniqueConstraint.UniqueConstraintProperties.Last().Property, relationshipProperty.Property);
            //---------------Execute Test ----------------------
            bool hasAllAkProps = dmRelationship.HasAllAkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllAkProps);
        }
/*
        [Test]
        public void Test_HasAllAKProps_False_WhenDoesNotHaveAllAKProps_SomePropsMatch_SameNoOfProps()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = CreateClassWithAkAndRelationship();
            DMProperty dmProperty1 = dmClass.Properties.CreateBusinessObject();
            DMProperty dmProperty2 = dmClass.Properties.CreateBusinessObject();
            DMUniqueConstraint uniqueConstraint = dmClass.UniqueConstraints[0];
            uniqueConstraint.AddPropertyInfo(dmProperty1);
            DMRelationship dmRelationship = dmClass.OwnerRelationships[0];
            DMRelationshipProperty relationshipProperty = dmRelationship.RelationshipProperties.CreateBusinessObject();
            relationshipProperty.Property = dmProperty2;
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, uniqueConstraint.Properties.Count);
            Assert.AreEqual(2, dmRelationship.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool hasAllAkProps = dmRelationship.HasAllAkProps();
            //---------------Test Result -----------------------
            Assert.IsFalse(hasAllAkProps);
        }*/

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSingle_WithMultipleReverse_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationship = (DMRelationship)TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass).ReverseRelationship;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single,relationship.Cardinality);
            Assert.AreEqual(Cardinality.Multiple,relationship.ReverseRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef) relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsTrue(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenMultiple_WithSingleReverse_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationship = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsFalse(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSingleFK_WithSingleReversePK_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty pkProp = parentClass.ObjectIdentity.Properties[0];
            DMProperty fkProp = childClass.NonOIDProperties[0];
            DMRelationship relationship = (DMRelationship)TestUtilsDMRelationship.CreateDMRelationshipOnProps(pkProp, fkProp).ReverseRelationship;
            relationship.ReverseRelationship.Cardinality = Cardinality.Single;
            relationship.ReverseRelationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreSame(fkProp, relationship.RelationshipProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            Assert.AreSame(pkProp, relationship.ReverseRelationship.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsTrue(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSingleAK_WithSingleReversePK_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty pkProp = parentClass.ObjectIdentity.Properties[0];
            DMProperty akProp = childClass.NonOIDProperties[0];
            DMUniqueConstraint uniqueConstraint = new DMUniqueConstraint { Class = childClass };
            uniqueConstraint.UniqueConstraintProperties.Add(new DMUniqueConstraintProperty { Property = akProp });
            DMRelationship relationship = (DMRelationship)TestUtilsDMRelationship.CreateDMRelationshipOnProps(pkProp, akProp).ReverseRelationship;
            relationship.ReverseRelationship.Cardinality = Cardinality.Single;
            relationship.ReverseRelationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.AreSame(uniqueConstraint, childClass.UniqueConstraints[0]);
            Assert.AreSame(akProp, uniqueConstraint.UniqueConstraintProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreSame(akProp, relationship.RelationshipProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            Assert.AreSame(pkProp, relationship.ReverseRelationship.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsTrue(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSinglePK_WithSingleReverseAK_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty pkProp = parentClass.ObjectIdentity.Properties[0];
            DMProperty akProp = childClass.NonOIDProperties[0];
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(childClass, akProp);
            DMRelationship relationship = TestUtilsDMRelationship.CreateDMRelationshipOnProps(pkProp, akProp);
            relationship.Cardinality = Cardinality.Single;
            relationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.AreSame(uniqueConstraint, childClass.UniqueConstraints[0]);
            Assert.AreSame(akProp, uniqueConstraint.UniqueConstraintProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            Assert.AreSame(akProp, relationship.ReverseRelationship.RelationshipProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreSame(pkProp, relationship.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsFalse(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSingleAK_WithSingleReverseAK_AndWithLesserName_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty ak1Prop = parentClass.NonOIDProperties[0];
            DMProperty ak2Prop = childClass.NonOIDProperties[0];
            DMUniqueConstraint uniqueConstraint1 = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ak1Prop);
            DMUniqueConstraint uniqueConstraint2 = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(childClass, ak2Prop);
            DMRelationship relationship = TestUtilsDMRelationship.CreateDMRelationshipOnProps(ak1Prop, ak2Prop);
            relationship.RelationshipName = "a" + relationship.RelationshipName;
            relationship.ReverseRelationship.RelationshipName = "b" + relationship.ReverseRelationship.RelationshipName;
            relationship.Cardinality = Cardinality.Single;
            relationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.That(relationship.RelationshipName, Is.LessThan(relationship.ReverseRelationship.RelationshipName));
            Assert.AreSame(uniqueConstraint1, parentClass.UniqueConstraints[0]);
            Assert.AreSame(ak1Prop, uniqueConstraint1.UniqueConstraintProperties[0].Property);
            Assert.AreSame(uniqueConstraint2, childClass.UniqueConstraints[0]);
            Assert.AreSame(ak2Prop, uniqueConstraint2.UniqueConstraintProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreSame(ak1Prop, relationship.RelationshipProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            Assert.AreSame(ak2Prop, relationship.ReverseRelationship.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsTrue(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSingleAK_WithSingleReverseAK_AndWithGreaterName_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty ak1Prop = parentClass.NonOIDProperties[0];
            DMProperty ak2Prop = childClass.NonOIDProperties[0];
            DMUniqueConstraint uniqueConstraint1 = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ak1Prop);
            DMUniqueConstraint uniqueConstraint2 = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(childClass, ak2Prop);
            DMRelationship relationship = TestUtilsDMRelationship.CreateDMRelationshipOnProps(ak1Prop, ak2Prop);
            relationship.RelationshipName = "b" + relationship.RelationshipName;
            relationship.ReverseRelationship.RelationshipName = "a" + relationship.ReverseRelationship.RelationshipName;
            relationship.Cardinality = Cardinality.Single;
            relationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.That(relationship.RelationshipName, Is.GreaterThan(relationship.ReverseRelationship.RelationshipName));
            Assert.AreSame(uniqueConstraint1, parentClass.UniqueConstraints[0]);
            Assert.AreSame(ak1Prop, uniqueConstraint1.UniqueConstraintProperties[0].Property);
            Assert.AreSame(uniqueConstraint2, childClass.UniqueConstraints[0]);
            Assert.AreSame(ak2Prop, uniqueConstraint2.UniqueConstraintProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreSame(ak1Prop, relationship.RelationshipProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            Assert.AreSame(ak2Prop, relationship.ReverseRelationship.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsFalse(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSinglePK_WithSingleReversePK_AndWithLesserName_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty pk1Prop = parentClass.ObjectIdentity.Properties[0];
            DMProperty pk2Prop = childClass.ObjectIdentity.Properties[0];
            DMRelationship relationship = TestUtilsDMRelationship.CreateDMRelationshipOnProps(pk1Prop, pk2Prop);
            relationship.RelationshipName = "a" + relationship.RelationshipName;
            relationship.ReverseRelationship.RelationshipName = "b" + relationship.ReverseRelationship.RelationshipName;
            relationship.Cardinality = Cardinality.Single;
            relationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.That(relationship.RelationshipName, Is.LessThan(relationship.ReverseRelationship.RelationshipName));
            Assert.AreSame(pk1Prop, parentClass.ObjectIdentity.Properties[0]);
            Assert.AreSame(pk2Prop, childClass.ObjectIdentity.Properties[0]);
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreSame(pk1Prop, relationship.RelationshipProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            Assert.AreSame(pk2Prop, relationship.ReverseRelationship.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsTrue(owningBOHasForeignKey);
        }

        [Test]
        public void Test_OwningBOHasForeignKey_WhenSinglePK_WithSingleReversePK_AndWithGreaterName_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty pk1Prop = parentClass.ObjectIdentity.Properties[0];
            DMProperty pk2Prop = childClass.ObjectIdentity.Properties[0];
            DMRelationship relationship = TestUtilsDMRelationship.CreateDMRelationshipOnProps(pk1Prop, pk2Prop);
            relationship.RelationshipName = "b" + relationship.RelationshipName;
            relationship.ReverseRelationship.RelationshipName = "a" + relationship.ReverseRelationship.RelationshipName;
            relationship.Cardinality = Cardinality.Single;
            relationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.That(relationship.RelationshipName, Is.GreaterThan(relationship.ReverseRelationship.RelationshipName));
            Assert.AreSame(pk1Prop, parentClass.ObjectIdentity.Properties[0]);
            Assert.AreSame(pk2Prop, childClass.ObjectIdentity.Properties[0]);
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreSame(pk1Prop, relationship.RelationshipProperties[0].Property);
            Assert.AreEqual(Cardinality.Single, relationship.ReverseRelationship.Cardinality);
            Assert.AreSame(pk2Prop, relationship.ReverseRelationship.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool owningBOHasForeignKey = ((IRelationshipDef)relationship).OwningBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsFalse(owningBOHasForeignKey);
        }

        [Test]
        public void Test_RelatedBOHasFK_WhenOwningBOHasFKTrue_ShouldRetFalse()
        {
            //---------------Set up test pack-------------------
            var fakeDMRelationship = new FakeDMRelationship();
            fakeDMRelationship.SetOwningBOHasForeignKey(true);
            //---------------Assert Precondition----------------
            Assert.IsTrue(fakeDMRelationship.OwningBOHasForeignKey);
            //---------------Execute Test ----------------------
            var relatedBOHasForeignKey = fakeDMRelationship.RelatedBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsFalse(relatedBOHasForeignKey);
        }
        [Test]
        public void Test_RelatedBOHasFK_WhenOwningBOHasFKFalse_ShouldRetTrue()
        {
            //---------------Set up test pack-------------------
            var fakeDMRelationship = new FakeDMRelationship();
            fakeDMRelationship.SetOwningBOHasForeignKey(false);
            //---------------Assert Precondition----------------
            Assert.IsFalse(fakeDMRelationship.OwningBOHasForeignKey);
            //---------------Execute Test ----------------------
            var relatedBOHasForeignKey = fakeDMRelationship.RelatedBOHasForeignKey;
            //---------------Test Result -----------------------
            Assert.IsTrue(relatedBOHasForeignKey);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenEmpty_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            relationshipOnParentClass.RelationshipProperties[0].MarkForDelete();
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(0, relationshipOnParentClass.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenEmpty_AndPKEmpty_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            relationshipOnParentClass.RelationshipProperties[0].MarkForDelete();
            parentClass.ObjectIdentity.Properties[0].MarkForDelete();
            //---------------Assert Precondition----------------
            Assert.AreEqual(0, parentClass.ObjectIdentity.Properties.Count);
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(0, relationshipOnParentClass.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenNullDMClass_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            bool ownerPropertiesPreviouslyConstitutedPK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            relationshipOnParentClass.ClassDM = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(ownerPropertiesPreviouslyConstitutedPK);
            Assert.IsNull(relationshipOnParentClass.ClassDM);
            Assert.AreEqual(1, relationshipOnParentClass.RelationshipProperties.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenSinglePKProp_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreSame(parentClass.ObjectIdentity.Properties[0], relationshipOnParentClass.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsTrue(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenSingleNonPKProp_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            DMRelationship relationshipOnChildClass = (DMRelationship)relationshipOnParentClass.ReverseRelationship;
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreSame(parentClass.ObjectIdentity.Properties[0], relationshipOnParentClass.RelationshipProperties[0].Property);
            Assert.AreNotSame(childClass.ObjectIdentity.Properties[0], relationshipOnChildClass.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnChildClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenCompositePKProp_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.IsTrue(parentClass.ObjectIdentity.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[0].Property));
            Assert.IsTrue(parentClass.ObjectIdentity.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[1].Property));
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsTrue(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenPartCompositePKProp_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            relationshipOnParentClass.RelationshipProperties[1].MarkForDelete();
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.IsTrue(parentClass.ObjectIdentity.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[0].Property));
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenPartCompositeAlmostSameProps_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2);
            TestUtilsDMProperty.CreateUnsavedValidDMProperty(parentClass);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            relationshipOnParentClass.RelationshipProperties[1].Property = parentClass.NonOIDProperties[0];
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.IsTrue(parentClass.ObjectIdentity.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[0].Property));
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnParentClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstitutePK_WhenCompositeFKProp_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            DMRelationship relationshipOnChildClass = (DMRelationship)relationshipOnParentClass.ReverseRelationship;
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreSame(parentClass.ObjectIdentity.Properties[0], relationshipOnParentClass.RelationshipProperties[0].Property);
            Assert.AreNotSame(childClass.ObjectIdentity.Properties[0], relationshipOnChildClass.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstitutePK = relationshipOnChildClass.OwnerPropertiesConstitutePK;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstitutePK);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenEmpty_AndOwnerHasUCs_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, parentClass.NonOIDProperties[0]);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            relationshipOnParentClass.RelationshipProperties[0].MarkForDelete();
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(0, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(1, parentClass.UniqueConstraints.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenEmpty_AndHasNoUCs_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            relationshipOnParentClass.RelationshipProperties[0].MarkForDelete();
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(0, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(0, parentClass.UniqueConstraints.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenEmpty_AndHasEmptyUC_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            relationshipOnParentClass.RelationshipProperties[0].MarkForDelete();
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(0, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(1, parentClass.UniqueConstraints.Count);
            Assert.AreEqual(0, parentClass.UniqueConstraints[0].UniqueConstraintProperties.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenNullDMClass_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            IDMProperty ownerProperty = relationshipOnParentClass.RelationshipProperties[0].OwnerProperty;
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ownerProperty);
            bool ownerPropertiesPreviouslyConstitutedUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            relationshipOnParentClass.ClassDM = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(ownerPropertiesPreviouslyConstitutedUC);
            Assert.IsNull(relationshipOnParentClass.ClassDM);
            Assert.AreEqual(1, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(1, uniqueConstraint.Properties.Count);
            Assert.AreSame(uniqueConstraint.Properties[0], relationshipOnParentClass.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenHasProps_ButHasNoUCs_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(1, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(0, parentClass.UniqueConstraints.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenHasProps_AndHasEmptyUC_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(1, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(1, parentClass.UniqueConstraints.Count);
            Assert.AreEqual(0, parentClass.UniqueConstraints[0].UniqueConstraintProperties.Count);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenSingleProp_WithMatchingUC_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            IDMProperty ownerProperty = relationshipOnParentClass.RelationshipProperties[0].OwnerProperty;
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ownerProperty);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(1, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(1, uniqueConstraint.Properties.Count);
            Assert.AreSame(uniqueConstraint.Properties[0], relationshipOnParentClass.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsTrue(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenSingleProp_WithNoMatchingUC_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, parentClass.NonOIDProperties[0]);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(1, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(1, uniqueConstraint.Properties.Count);
            Assert.AreNotSame(uniqueConstraint.Properties[0], relationshipOnParentClass.RelationshipProperties[0].Property);
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenCompositeProps_WithMatchingUC_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            IDMProperty ownerProperty1 = relationshipOnParentClass.RelationshipProperties[0].OwnerProperty;
            IDMProperty ownerProperty2 = relationshipOnParentClass.RelationshipProperties[1].OwnerProperty;
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ownerProperty1, ownerProperty2);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.IsTrue(uniqueConstraint.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[0].Property));
            Assert.IsTrue(uniqueConstraint.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[1].Property));
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsTrue(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenSubsetOfUC_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            IDMProperty ownerProperty1 = relationshipOnParentClass.RelationshipProperties[0].OwnerProperty;
            DMProperty ownerProperty2 = parentClass.NonOIDProperties[0];
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ownerProperty1, ownerProperty2);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(1, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.IsTrue(uniqueConstraint.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[0].Property));
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenPartOfACompositeUCAlmostSameProps_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2, 2);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            IDMProperty ownerProperty1 = relationshipOnParentClass.RelationshipProperties[0].OwnerProperty;
            DMProperty ownerProperty2 = parentClass.NonOIDProperties[0];
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ownerProperty1, ownerProperty2);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(2, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(2, uniqueConstraint.Properties.Count);
            Assert.IsTrue(uniqueConstraint.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[0].Property));
            Assert.IsFalse(uniqueConstraint.Properties.Contains((DMProperty) relationshipOnParentClass.RelationshipProperties[1].Property));
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        [Test]
        public void Test_OwnerPropertiesConstituteUC_WhenSupersetOfUC_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2);
            DMClass childClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship relationshipOnParentClass = TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
            IDMProperty ownerProperty1 = relationshipOnParentClass.RelationshipProperties[0].OwnerProperty;
            DMUniqueConstraint uniqueConstraint = TestUtilsDMUniqueConstraint.CreateUniqueConstraint(parentClass, ownerProperty1);
            //---------------Assert Precondition----------------
            Assert.AreSame(parentClass, relationshipOnParentClass.ClassDM);
            Assert.AreEqual(2, relationshipOnParentClass.RelationshipProperties.Count);
            Assert.AreEqual(1, uniqueConstraint.Properties.Count);
            Assert.IsTrue(relationshipOnParentClass.RelationshipProperties.Exists(property => property.Property == uniqueConstraint.Properties[0]));
            //---------------Execute Test ----------------------
            bool ownerPropertiesConstituteUC = relationshipOnParentClass.OwnerPropertiesConstituteUC;
            //---------------Test Result -----------------------
            Assert.IsFalse(ownerPropertiesConstituteUC);
        }

        // =====================================================================================================================================





        [Test]
        public void Test_AreObjectIdsValid_WhenOwnerClassNotIsObjectIDValid_ShouldBFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClassWithNoOID(1);
            DMRelationship dmRelationship = new DMRelationship();
            dmClass.OwnerRelationships.Add(dmRelationship);
            //---------------Assert Precondition----------------
            Assert.IsFalse(dmClass.IsObjectIDValid);
            //---------------Execute Test ----------------------
            var areObjectIDsValid = dmRelationship.AreObjectIDsValid;
            //---------------Test Result -----------------------
            Assert.IsFalse(areObjectIDsValid);
        }

        [Test]
        public void Test_AreObjectIdsValid_WhenRelatedClassNotIsObjectIDValid_ShouldBFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship dmRelationship = new DMRelationship();
            dmClass.OwnerRelationships.Add(dmRelationship);
            DMClass relatedClass = TestUtilsDMClass.CreateSavedDMClassWithNoOID(0);
            dmRelationship.RelatedClass = relatedClass;
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.IsObjectIDValid);
            Assert.IsFalse(relatedClass.IsObjectIDValid);
            //---------------Execute Test ----------------------
            var areObjectIDsValid = dmRelationship.AreObjectIDsValid;
            //---------------Test Result -----------------------
            Assert.IsFalse(areObjectIDsValid);
        }
        [Test]
        public void Test_AreObjectIdsValid_WhenBothClassValidID_ShouldBTrue()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship dmRelationship = new DMRelationship();
            dmClass.OwnerRelationships.Add(dmRelationship);
            DMClass relatedClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            dmRelationship.RelatedClass = relatedClass;
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.IsObjectIDValid);
            Assert.IsTrue(relatedClass.IsObjectIDValid);
            //---------------Execute Test ----------------------
            var areObjectIDsValid = dmRelationship.AreObjectIDsValid;
            //---------------Test Result -----------------------
            Assert.IsTrue(areObjectIDsValid);
        }

        [Test]
        public void Test_AreObjectIdsValid_WhenRelatedClassNull_ShouldBFalse()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship dmRelationship = new DMRelationship();
            dmClass.OwnerRelationships.Add(dmRelationship);
            dmRelationship.RelatedClass = null;
            //---------------Assert Precondition----------------
            Assert.IsTrue(dmClass.IsObjectIDValid);
            Assert.IsNull(dmRelationship.RelatedClass);
            //---------------Execute Test ----------------------
            var areObjectIDsValid = dmRelationship.AreObjectIDsValid;
            //---------------Test Result -----------------------
            Assert.IsFalse(areObjectIDsValid);
        }
        [Test]
        public void Test_AreObjectIdsValid_WhenOwnerClassNull_ShouldBFalse()
        {
            //---------------Set up test pack-------------------
            DMClass relatedClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMRelationship dmRelationship = new DMRelationship 
                    {RelatedClass = relatedClass, OwnerClass = null};
            //---------------Assert Precondition----------------
            Assert.IsTrue(relatedClass.IsObjectIDValid);
            Assert.IsNull(dmRelationship.OwnerClass);
            Assert.AreSame(relatedClass, dmRelationship.RelatedClass);
            //---------------Execute Test ----------------------
            var areObjectIDsValid = dmRelationship.AreObjectIDsValid;
            //---------------Test Result -----------------------
            Assert.IsFalse(areObjectIDsValid);
        }

        [Test]
        public void TestIsCompositionOrAggregation_WhenComp_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.RelationshipType = RelationshipType.Composition;
            //---------------Assert Precondition----------------
            Assert.AreEqual(RelationshipType.Composition, dmRelationship.RelationshipType);
            //---------------Execute Test ----------------------
            bool isCompositionOrAggregation = dmRelationship.IsCompositionOrAggregation;
            //---------------Test Result -----------------------
            Assert.IsTrue(isCompositionOrAggregation);
        }

        [Test]
        public void TestIsCompositionOrAggregation_WhenAgg_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.RelationshipType = RelationshipType.Aggregation;
            //---------------Assert Precondition----------------
            Assert.AreEqual(RelationshipType.Aggregation, dmRelationship.RelationshipType);
            //---------------Execute Test ----------------------
            bool isCompositionOrAggregation = dmRelationship.IsCompositionOrAggregation;
            //---------------Test Result -----------------------
            Assert.IsTrue(isCompositionOrAggregation);
        }

        [Test]
        public void TestIsCompositionOrAggregation_WhenAssociation_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.RelationshipType = RelationshipType.Association;
            //---------------Assert Precondition----------------
            Assert.AreEqual(RelationshipType.Association, dmRelationship.RelationshipType);
            //---------------Execute Test ----------------------
            bool isCompositionOrAggregation = dmRelationship.IsCompositionOrAggregation;
            //---------------Test Result -----------------------
            Assert.IsFalse(isCompositionOrAggregation);
        }

        [Test]
        public void TestIsIsRelationshipSingle_WhenMultiple_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isRelationshipSingle = dmRelationship.IsSingle;
            //---------------Test Result -----------------------
            Assert.IsFalse(isRelationshipSingle);
        }

        [Test]
        public void TestIsIsRelationshipSingle_WhenSingle_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isRelationshipSingle = dmRelationship.IsSingle;
            //---------------Test Result -----------------------
            Assert.IsTrue(isRelationshipSingle);
        }

        [Test]
        public void TestIsRelationshipMultiple_WhenSingle_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isRelationshipMultiple = dmRelationship.IsMultiple;
            //---------------Test Result -----------------------
            Assert.IsFalse(isRelationshipMultiple);
        }

        
        [Test]
        public void TestIsRelationshipMultiple_WhenMultiple_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isRelationshipMultiple = dmRelationship.IsMultiple;
            //---------------Test Result -----------------------
            Assert.IsTrue(isRelationshipMultiple);
        }

        [Test]
        public void TestIsOneToMany_WhenManyToOne_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.ReverseRelationship.Cardinality);
            Assert.IsTrue(dmRelationship.IsManyToOne);
            //---------------Execute Test ----------------------
            bool isOneToMany = dmRelationship.IsOneToMany;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneToMany);
        }

        [Test]
        public void TestIsOneToMany_WhenOneToOne_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, dmRelationship.ReverseRelationship.Cardinality);
            Assert.IsTrue(dmRelationship.IsOneToOne);
            //---------------Execute Test ----------------------
            bool isOneToMany = dmRelationship.IsOneToMany;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneToMany);
        }

        [Test]
        public void TestIsOneToMany_WhenOneToMany_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Multiple;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, dmRelationship.ReverseRelationship.Cardinality);
            Assert.IsFalse(dmRelationship.IsOneToOne);
            Assert.IsFalse(dmRelationship.IsManyToOne);
            //---------------Execute Test ----------------------
            bool isOneToMany = dmRelationship.IsOneToMany;
            //---------------Test Result -----------------------
            Assert.IsTrue(isOneToMany);
        }

        [Test]
        public void TestIsOneToMany_WhenMultipleAndRevRelNull_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Multiple;
            SetReverseRelationshipNull(dmRelationship);
//            dmRelationship.ReverseRelationship = null;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.Cardinality);
            Assert.IsNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            bool isOneToMany = dmRelationship.IsOneToMany;
            //---------------Test Result -----------------------
            Assert.IsTrue(isOneToMany);
        }
        [Test]
        public void TestIsOneToOne_WhenOneToMany_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.ReverseRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isOneToOne = dmRelationship.IsOneToOne;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneToOne);
        }

        [Test]
        public void TestIsOneToOne_WhenManyToOne_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Multiple;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, dmRelationship.ReverseRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isOneToOne = dmRelationship.IsOneToOne;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneToOne);
        }

        [Test]
        public void TestIsOneToOne_WhenOneToOne_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, dmRelationship.ReverseRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isOneToOne = dmRelationship.IsOneToOne;
            //---------------Test Result -----------------------
            Assert.IsTrue(isOneToOne);
        }
        [Test]
        public void TestIsOneToOne_WhenSingle_AndRevRelNull_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            SetReverseRelationshipNull(dmRelationship);
//            dmRelationship.ReverseRelationship = null;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.IsNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            bool isOneToOne = dmRelationship.IsOneToOne;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneToOne);
        }


        [Test]
        public void TestIsManyToOne_WhenOneToMany_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Multiple;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, dmRelationship.ReverseRelationship.Cardinality);
            Assert.IsTrue(dmRelationship.IsOneToMany);
            //---------------Execute Test ----------------------
            bool isManyToOne = dmRelationship.IsManyToOne;
            //---------------Test Result -----------------------
            Assert.IsFalse(isManyToOne);
        }

        [Test]
        public void TestIsManyToOne_WhenOneToOne_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Single, dmRelationship.ReverseRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isManyToOne = dmRelationship.IsManyToOne;
            //---------------Test Result -----------------------
            Assert.IsFalse(isManyToOne);
        }

        [Test]
        public void TestIsManyToOne_WhenManyToOne_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            dmRelationship.ReverseRelationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.AreEqual(Cardinality.Multiple, dmRelationship.ReverseRelationship.Cardinality);
            //---------------Execute Test ----------------------
            bool isManyToOne = dmRelationship.IsManyToOne;
            //---------------Test Result -----------------------
            Assert.IsTrue(isManyToOne);
        }
        [Test]
        public void TestIsManyToOne_WhenSingleAndRevRelNull_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Single;
            SetReverseRelationshipNull(dmRelationship);
//            dmRelationship.ReverseRelationship = null;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Single, dmRelationship.Cardinality);
            Assert.IsNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            bool isManyToOne = dmRelationship.IsManyToOne;
            //---------------Test Result -----------------------
            Assert.IsTrue(isManyToOne);
        }

        private void SetReverseRelationshipNull(DMRelationship dmRelationship)
        {
            dmRelationship.Relationships.SetRelatedObject("ReverseRelationship", null);
        }

        [Test]
        public void Test_ResetReverseRelationship_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            try
            {
                dmRelationship.ReverseRelationship = new DMRelationship(null);
                Assert.Fail("Expected to throw an HabaneroDeveloperException");
            }
                //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("cannot be changed once it is set", ex.Message);
            }
        }
        //This is only needed because other tests require it.
        [Test]
        public void Test_ResetReverseRelationshipToNull_ShouldBeAllowed()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            dmRelationship.ReverseRelationship = null;
            //---------------Test Result -----------------------
            Assert.IsNull(dmRelationship.ReverseRelationship);
        }
        [Test]
        public void Test_ResetReverseRelationship_WhenWasNull_ShouldBeAllowed()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship(null);
            //---------------Assert Precondition----------------
            Assert.IsNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            dmRelationship.ReverseRelationship = new DMRelationship(null);
            //---------------Test Result -----------------------
            Assert.IsNotNull(dmRelationship.ReverseRelationship);
        }

        [Test]
        public void Test_SetRelatedClass_WhenReverseRelationshipNull_ShouldSetRelatedClassNameAndRelatedAssemblyName()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship(null);
            var relatedClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmRelationship.ReverseRelationship);
            Assert.IsNotNullOrEmpty(relatedClass.ClassNameBO);
            Assert.IsNotNullOrEmpty(relatedClass.Assembly.AssemblyName);
            //---------------Execute Test ----------------------
            dmRelationship.RelatedClass = relatedClass;
            //---------------Test Result -----------------------
            Assert.AreEqual(relatedClass.ClassNameBO, dmRelationship.RelatedClassName);
            Assert.AreEqual(relatedClass.AssemblyName, dmRelationship.RelatedAssemblyName);
        }

        [Test]
        public void Test_SetRelatedClass_WhenReverseRelationshipNotNull_ShouldSet()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            var relatedClass = new DMClass();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            dmRelationship.RelatedClass = relatedClass;
            //---------------Test Result -----------------------
            Assert.AreSame(relatedClass, dmRelationship.RelatedClass);
        }
        [Test]
        public void Test_SetRelatedClassToNull_WhenReverseRelationshipNull_ShouldDoNothing()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship(null);
            //---------------Assert Precondition----------------
            Assert.IsNull(dmRelationship.ReverseRelationship);
            Assert.IsNull(dmRelationship.RelatedClass);
            //---------------Execute Test ----------------------
            dmRelationship.RelatedClass = null;
            //---------------Test Result -----------------------
            Assert.IsNull(dmRelationship.RelatedClass);
        }

        [Test]
        public void Test_HasReverseRelDefined_WhenRevRelNull_ShouldRetFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship(null);
            //---------------Assert Precondition----------------
            Assert.IsNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            bool hasReverseRelationship = dmRelationship.HasReverseRelationship;
            //---------------Test Result -----------------------
            Assert.IsFalse(hasReverseRelationship);
        }
        [Test]
        public void Test_HasReverseRelDefined_WhenRevRelNotNull_ShouldRetTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            bool hasReverseRelationship = dmRelationship.HasReverseRelationship;
            //---------------Test Result -----------------------
            Assert.IsTrue(hasReverseRelationship);
        }

        [Test]
        public void Test_SetCardinality_WhenRevRelAK_ShouldSetChangeRelationshipToSingle()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithRRelAKTrue();
            relationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.ReverseRelationship.HasAllPkProps());
            Assert.IsTrue(relationship.ReverseRelationship.HasAllAkProps());
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
        }
        [Test]
        public void Test_SetCardinality_WhenChangesAndRelNameIsRelatedClassNamePluralised_ShouldChangeRelName()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithRRelAKTrue();
            const string relatedClassName = "SomeClass";
            relationship.RelatedClassName = relatedClassName;
            relationship.Cardinality = Cardinality.Multiple;
            relationship.RelationshipName = new RelationshipNameGenerator().CreateRelationshipName(relationship);
            relationship.RelationshipName = StringUtilities.Pluralize(relatedClassName);
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            Assert.AreEqual(StringUtilities.Pluralize(relatedClassName), relationship.RelationshipName);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreEqual(StringUtilities.Singularize(relatedClassName), relationship.RelationshipName);

        }

        [Test]
        public void Test_SetCardinality_WhenChangesAndRelNameIsNotRelatedClassNamePluralised_ShouldNotChangeRelName()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithRRelAKTrue();
            const string relatedClassName = "SomeClass";
            relationship.RelatedClassName = relatedClassName;
            relationship.Cardinality = Cardinality.Multiple;
            
            relationship.RelationshipName = GetRandomString();
            var origionalRelationshipName = relationship.RelationshipName;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(relationship.RelationshipName);
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            Assert.AreNotEqual(StringUtilities.Pluralize(relatedClassName), origionalRelationshipName);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreNotEqual(StringUtilities.Singularize(relatedClassName), relationship.RelationshipName);
            Assert.AreEqual(origionalRelationshipName,  relationship.RelationshipName);
        }
        [Test]
        public void Test_SetCardinality_WhenChangesAndRelNameNull_ShouldSetRelName()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithRRelAKTrue();
            const string relatedClassName = "SomeClass";
            relationship.RelatedClassName = relatedClassName;
            relationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            Assert.IsNull(relationship.RelationshipName);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreEqual(StringUtilities.Singularize(relatedClassName), relationship.RelationshipName);
        }

        [Test]
        public void Test_SetCardinality_WhenChanges_ShouldDeleteParentActionDoNothing()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithRRelAKTrue();
            const string relatedClassName = "SomeClass";
            relationship.RelatedClassName = relatedClassName;
            relationship.Cardinality = Cardinality.Multiple;
            relationship.RelationshipName = new RelationshipNameGenerator().CreateRelationshipName(relationship);
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            Assert.AreNotEqual(DeleteParentAction.DoNothing, relationship.DeleteAction);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreEqual(DeleteParentAction.DoNothing, relationship.DeleteAction);

        }

        [Test]
        public void Test_SetCardinality_WhenChange_ShouldNotResetDeleteParentAction()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithAKFalseAndPKFalse();
            relationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            Assert.AreNotEqual(DeleteParentAction.DoNothing, relationship.DeleteAction);

            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            Assert.AreNotEqual(DeleteParentAction.DoNothing, relationship.DeleteAction);

        }
        [Test]
        public void Test_SetCardinality_WhenRRelPK_ShouldSetChangeRelationshipToSingle()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithRRelPKTrue();
            relationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationship.ReverseRelationship.HasAllPkProps());
            Assert.IsFalse(relationship.ReverseRelationship.HasAllAkProps());
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
        }

        [Test]
        public void Test_SetCardinality_WhenNotAKAndNotPK_ShouldNotChangeRel()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithAKFalseAndPKFalse();
            relationship.Cardinality = Cardinality.Multiple;
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.ReverseRelationship.HasAllPkProps());
            Assert.IsFalse(relationship.ReverseRelationship.HasAllAkProps());
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Multiple, relationship.Cardinality);
        }

        [Test]
        public void Test_SetCardinality_WhenNotAKAndSingle_ShouldNotChangeRel()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithAKFalseAndPKFalse();
            relationship.Cardinality = Cardinality.Single;
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.ReverseRelationship.HasAllPkProps());
            Assert.IsFalse(relationship.ReverseRelationship.HasAllAkProps());
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
        }
        [Test]
        public void Test_SetCardinality_WhenAKAndSingle_ShouldNotRename()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = GetStubDMRelationshipWithRRelAKTrue();
            relationship.RelationshipName = GetRandomString();
            relationship.RelatedClassName = GetRandomString();
            relationship.Cardinality = Cardinality.Single;
            var origRelName = relationship.RelationshipName;
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.ReverseRelationship.HasAllPkProps());
            Assert.IsTrue(relationship.ReverseRelationship.HasAllAkProps());
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.IsNotNullOrEmpty(origRelName);
            Assert.IsNotNullOrEmpty(relationship.RelatedClassName);
            //---------------Execute Test ----------------------
            relationship.ResetCardinality();
            //---------------Test Result -----------------------
            Assert.AreEqual(Cardinality.Single, relationship.Cardinality);
            Assert.AreEqual(origRelName, relationship.RelationshipName);
        }

        [Test]
        public void Test_OwnerClassName_WhenNoOwnerClass_ShouldReturnEmptyString()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = new DMRelationship(null);

            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.OwnerClass);
            //---------------Execute Test ----------------------
            var ownerClassName = relationship.OwnerClassName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", ownerClassName);
        }
        [Test]
        public void Test_OwnerClassName_WhenHasOwnerClass_ShouldReturnOwnerClasssName()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass;
            DMRelationship relationship = GetRelationshipWithOwnerClass(out dmClass);
            dmClass.ClassNameBO = GetRandomString();
            //---------------Assert Precondition----------------
            Assert.AreSame(dmClass, relationship.OwnerClass);
            Assert.IsNotNullOrEmpty(dmClass.ClassNameBO);
            //---------------Execute Test ----------------------
            var ownerClassName = relationship.OwnerClassName;
            //---------------Test Result -----------------------
            Assert.AreEqual(dmClass.ClassNameBO, ownerClassName);
        }

        [Test]
        public void Test_OwnerClassAssemblyName_WhenNoOwnerClass_ShouldReturnEmptyString()
        {
            //---------------Set up test pack-------------------
            DMRelationship relationship = new DMRelationship(null);

            //---------------Assert Precondition----------------
            Assert.IsNull(relationship.OwnerClass);
            //---------------Execute Test ----------------------
            var ownerClassAssemblyName = relationship.OwnerClassAssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual("", ownerClassAssemblyName);
        }

        [Test]
        public void Test_OwnerClassAssemblyName_WhenHasOwnerClass_ShouldReturnOwnerClasssAssemblyName()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass;
            DMRelationship relationship = GetRelationshipWithOwnerClass(out dmClass);
            dmClass.Assembly.AssemblyName = GetRandomString();
            //---------------Assert Precondition----------------
            Assert.AreSame(dmClass, relationship.OwnerClass);
            Assert.IsNotNullOrEmpty(dmClass.AssemblyName);
            //---------------Execute Test ----------------------
            var ownerClassAssemblyName = relationship.OwnerClassAssemblyName;
            //---------------Test Result -----------------------
            Assert.AreEqual(dmClass.AssemblyName, ownerClassAssemblyName);
        }

        [Test]
        public void Test_IsOneDeleteActionDoNothing_WhenBothHaveDeletePrevent_ShouldBFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.DeleteAction = DeleteParentAction.Prevent;
            dmRelationship.ReverseRelationship.DeleteAction = DeleteParentAction.Prevent;

            //---------------Assert Precondition----------------
            Assert.AreEqual(DeleteParentAction.Prevent, dmRelationship.DeleteAction);
            Assert.AreEqual(DeleteParentAction.Prevent, dmRelationship.ReverseRelationship.DeleteAction);
            //---------------Execute Test ----------------------
            bool isOneDoNothing = dmRelationship.IsOneDeleteActionDoNothing;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneDoNothing);
        }

        [Test]
        public void Test_IsOneDeleteActionDoNothing_WhenOneDoNothing_ShouldBTrue()
        {
            //Although this is invalid it will be picked up by the reverse relationship being validated
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.DeleteAction = DeleteParentAction.Prevent;
            dmRelationship.ReverseRelationship.DeleteAction = DeleteParentAction.DoNothing;
            //---------------Assert Precondition----------------
            Assert.AreEqual(DeleteParentAction.Prevent, dmRelationship.DeleteAction);
            Assert.AreEqual(DeleteParentAction.DoNothing, dmRelationship.ReverseRelationship.DeleteAction);
            //---------------Execute Test ----------------------
            bool isOneDoNothing = dmRelationship.IsOneDeleteActionDoNothing;
            //---------------Test Result -----------------------
            Assert.IsTrue(isOneDoNothing);
        }
        [Test]
        public void Test_IsOneDeleteActionDoNothing_WhenOtherDoNothing_ShouldBTrue()
        {
            //Although this is invalid it will be picked up by the reverse relationship being validated
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.DeleteAction = DeleteParentAction.DoNothing;
            dmRelationship.ReverseRelationship.DeleteAction = DeleteParentAction.Prevent;
            //---------------Assert Precondition----------------
            Assert.AreEqual(DeleteParentAction.DoNothing, dmRelationship.DeleteAction);
            Assert.AreEqual(DeleteParentAction.Prevent, dmRelationship.ReverseRelationship.DeleteAction);
            //---------------Execute Test ----------------------
            bool isOneDoNothing = dmRelationship.IsOneDeleteActionDoNothing;
            //---------------Test Result -----------------------
            Assert.IsTrue(isOneDoNothing);
        }
        [Test]
        public void Test_IsOneDeleteActionDoNothing_WhenOtherDeleteRelated_ShouldBFalse()
        {
            //Although this is invalid it will be picked up by the reverse relationship being validated
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.DeleteAction = DeleteParentAction.DeleteRelated;
            dmRelationship.ReverseRelationship.DeleteAction = DeleteParentAction.Prevent;
            //---------------Assert Precondition----------------
            Assert.AreEqual(DeleteParentAction.DeleteRelated, dmRelationship.DeleteAction);
            Assert.AreEqual(DeleteParentAction.Prevent, dmRelationship.ReverseRelationship.DeleteAction);
            //---------------Execute Test ----------------------
            bool isOneDoNothing = dmRelationship.IsOneDeleteActionDoNothing;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneDoNothing);
        }
        [Test]
        public void Test_IsOneDeleteActionDoNothing_WhenOneDerefRelated_ShouldBFalse()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.DeleteAction = DeleteParentAction.DereferenceRelated;
            dmRelationship.ReverseRelationship.DeleteAction = DeleteParentAction.Prevent;
            //---------------Assert Precondition----------------
            Assert.AreEqual(DeleteParentAction.DereferenceRelated, dmRelationship.DeleteAction);
            //---------------Execute Test ----------------------
            bool isOneDoNothing = dmRelationship.IsOneDeleteActionDoNothing;
            //---------------Test Result -----------------------
            Assert.IsFalse(isOneDoNothing);
        }
        [Test]
        public void Test_IsOneDeleteActionDoNothing_WhenRevRelNull_ShouldBTrue()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship(null);
            dmRelationship.DeleteAction = DeleteParentAction.Prevent;
            //---------------Assert Precondition----------------
            Assert.AreEqual(DeleteParentAction.Prevent, dmRelationship.DeleteAction);
            Assert.IsNull(dmRelationship.ReverseRelationship);
            //---------------Execute Test ----------------------
            bool isOneDoNothing = dmRelationship.IsOneDeleteActionDoNothing;
            //---------------Test Result -----------------------
            Assert.IsTrue(isOneDoNothing);
        }

        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = new DMClass();
            DMRelationship dmRelationship = new DMRelationship();
            dmClass.OwnerRelationships.Add(dmRelationship);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelRelationship)dmRelationship).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(dmClass, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelRelationship modelRelationship = new DMRelationship();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                modelRelationship.Parent = new DMClass();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the Relationship by setting the related OwnerClass object", exceptionThrown.Message);
        }

        [Test]
        public void Test_RelatedAssembly()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            DMClass relatedClass = new DMClass();
            dmRelationship.RelatedClass = relatedClass;
            string expectedAssemblyName = GetRandomString();
            relatedClass.Assembly = new DMAssembly(expectedAssemblyName);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string assemblyName = ((IModelRelationship)dmRelationship).RelatedAssembly;

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedAssemblyName, assemblyName);
        }

        [Test]
        public void Test_RelatedAssembly_NullClass_ThrowsException()
        {
            //---------------Set up test pack-------------------
            IModelRelationship modelRelationship = new DMRelationship();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string assemblyName = modelRelationship.RelatedAssembly;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains("Related class was null when accessing RelatedAssembly", exceptionThrown.Message);
        }


        [Test]
        public void Test_RelatedAssembly_NullAssembly_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            DMClass relatedClass = new DMClass();
            dmRelationship.RelatedClass = relatedClass;

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string assemblyName = ((IModelRelationship)dmRelationship).RelatedAssembly;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains("Related assembly was null when accessing RelatedAssembly", exceptionThrown.Message);
        }

        [Test]
        public void Test_IsMultiple()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.Cardinality = Cardinality.Multiple;

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isMultiple = ((IModelRelationship)dmRelationship).IsMultiple;
            //---------------Test Result -----------------------
            Assert.IsTrue(isMultiple);
        }

        [Test]
        public void Test_Property()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();

            DMClass dmClass = new DMClass();
            dmRelationship.OwnerClass = dmClass;
            DMProperty expectedProperty = new DMProperty();
            dmClass.Properties.Add(expectedProperty);
            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationshipProperty.OwnerProperty = expectedProperty;
            dmRelationship.RelationshipProperties.Add(dmRelationshipProperty);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelProperty property = ((IModelRelationship)dmRelationship).Property;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedProperty, property);
        }

        [Test]
        public void Test_Property_NoProperty_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                IModelProperty property = ((IModelRelationship)dmRelationship).Property;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("There are no properties for the relationship when accessing the OwnerProperty for the '' relationship on ''", exceptionThrown.Message);
        }

        [Test]
        public void Test_RelatedProperty()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();

            DMClass dmClass = new DMClass();
            dmRelationship.RelatedClass = dmClass;
            DMProperty expectedProperty = new DMProperty();
            dmClass.Properties.Add(expectedProperty);
            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationshipProperty.RelatedProperty = expectedProperty;
            dmRelationship.RelationshipProperties.Add(dmRelationshipProperty);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelProperty property = ((IModelRelationship)dmRelationship).RelatedProperty;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedProperty, property);
        }

        [Test]
        public void Test_RelatedProperty_NoProperty_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                IModelProperty property = ((IModelRelationship)dmRelationship).RelatedProperty;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("There are no properties for the relationship when accessing the RelatedProperty",
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_RelatedPropertyName()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();

            DMClass dmClass = new DMClass();
            dmRelationship.RelatedClass = dmClass;
            DMProperty expectedProperty = new DMProperty();
            dmClass.Properties.Add(expectedProperty);
            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationshipProperty.RelatedProperty = expectedProperty;
            string expectedRelatedPropertyName = GetRandomString();
            dmRelationship.RelationshipProperties.Add(dmRelationshipProperty);
            expectedProperty.PropertyName = expectedRelatedPropertyName;

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string relatedPropertyName = ((IModelRelationship)dmRelationship).RelatedPropertyName;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedRelatedPropertyName, relatedPropertyName);
        }

        [Test]
        public void Test_RelatedPropertyName_NoProperties_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string relatedPropertyName = ((IModelRelationship)dmRelationship).RelatedPropertyName;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("There are no properties for the relationship when accessing the RelatedPropertyName",
                 exceptionThrown.Message);
        }

        [Test]
        public void Test_RelatedPropertyName_NoRelatedProperty_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationship.RelationshipProperties.Add(dmRelationshipProperty);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string relatedPropertyName = ((IModelRelationship)dmRelationship).RelatedPropertyName;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("The related property not set when accessing the RelatedPropertyName", exceptionThrown.Message);
        }

        [Test]
        public void Test_PropertyName()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();

            DMClass dmClass = new DMClass();
            dmRelationship.OwnerClass = dmClass;
            DMProperty expectedProperty = new DMProperty();
            dmClass.Properties.Add(expectedProperty);
            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationshipProperty.OwnerProperty = expectedProperty;
            string expectedPropertyName = GetRandomString();
            dmRelationship.RelationshipProperties.Add(dmRelationshipProperty);
            expectedProperty.PropertyName = expectedPropertyName;

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string propertyName = ((IModelRelationship)dmRelationship).PropertyName;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedPropertyName, propertyName);
        }

        [Test]
        public void Test_PropertyName_NoProperties_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string propertyName = ((IModelRelationship)dmRelationship).PropertyName;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("There are no properties for the relationship ", exceptionThrown.Message);
            StringAssert.Contains
                ("when accessing the PropertyName", exceptionThrown.Message);
        }

        [Test]
        public void Test_PropertyName_NoOwnerProperty_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationship.RelationshipProperties.Add(dmRelationshipProperty);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string propertyName = ((IModelRelationship)dmRelationship).PropertyName;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains("The owner property for the relationship", exceptionThrown.Message);
            StringAssert.Contains(" not set when accessing the PropertyName", exceptionThrown.Message);
        }

        [Test]
        public void Test_DeleteParentAction_DoNothing()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            const DeleteParentAction expectedDeleteAction = DeleteParentAction.DoNothing;
            dmRelationship.DeleteAction = expectedDeleteAction;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            //DeleteParentAction deleteParentAction = ((IModelRelationship)dmRelationship).DeleteParentAction;
            string deleteParentAction = ((IModelRelationship)dmRelationship).DeleteParentAction;

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedDeleteAction.ToString(), deleteParentAction);
        }

        [Test]
        public void Test_DeleteParentAction_RaisesError_WhenDeleteActionIsNull()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            dmRelationship.DeleteAction = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(dmRelationship.DeleteAction);
            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string deleteParentAction = ((IModelRelationship)dmRelationship).DeleteParentAction;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains("DeleteAction has a null value for the relationship '" + dmRelationship.RelationshipName + "'", exceptionThrown.Message);
        }

        [Test]
        public void Test_RelatedClass()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();

            DMClass dmClass = new DMClass();
            dmRelationship.RelatedClass = dmClass;

            string expectedRelatedClassName = GetRandomString();

            dmClass.ClassNameBO = expectedRelatedClassName;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string relatedClassName = ((IModelRelationship)dmRelationship).RelatedClass;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedRelatedClassName, relatedClassName);
        }

        private string GetRandomString()
        {
            return TestUtilsShared.GetRandomString();
        }

        [Test]
        public void Test_RelatedClass_Null_ThrowsException()
        {
            //---------------Set up test pack-------------------
            DMRelationship dmRelationship = new DMRelationship();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                string relatedClassName = ((IModelRelationship)dmRelationship).RelatedClass;
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains("Related class not set when accessing the RelatedClass", exceptionThrown.Message);
        }

        [Test]
        public void Test_AllOwnerPropertiesAreCompulsory__WhenHasOneCompulsoryOwnerPropOneNot_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            FakeDMRelationship relationship = new FakeDMRelationship();
            FakeBusinessObjectCollection<DMRelationshipProperty> relationshipProperties = new FakeBusinessObjectCollection<DMRelationshipProperty>();
            DMProperty ownerProperty = AddOwnerProperty(relationshipProperties, true);
            DMProperty ownerProperty2 = AddOwnerProperty(relationshipProperties, false);
            relationship.SetRelationshipProperties(relationshipProperties);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, relationship.RelationshipProperties.Count);
            Assert.IsTrue(ownerProperty.Compulsory.GetValueOrDefault());
            Assert.IsFalse(ownerProperty2.Compulsory.GetValueOrDefault());
            //---------------Execute Test ----------------------
            bool compulsory = relationship.AllOwnerPropertiesAreCompulsory;
            //---------------Test Result -----------------------
            Assert.IsFalse(compulsory, "Should be compulsory");
        }
        [Test]
        public void Test_AllOwnerPropertiesAreCompulsory__WhenHasOneNonCompulsoryOwnerProp_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            FakeDMRelationship relationship = new FakeDMRelationship();
            FakeBusinessObjectCollection<DMRelationshipProperty> relationshipProperties = new FakeBusinessObjectCollection<DMRelationshipProperty>();
            DMProperty ownerProperty = AddOwnerProperty(relationshipProperties, false);
            relationship.SetRelationshipProperties(relationshipProperties);
            //---------------Assert Precondition----------------
            Assert.IsNotEmpty(relationship.RelationshipProperties);
            Assert.IsFalse(ownerProperty.Compulsory.GetValueOrDefault());
            //---------------Execute Test ----------------------
            bool compulsory = relationship.AllOwnerPropertiesAreCompulsory;
            //---------------Test Result -----------------------
            Assert.IsFalse(compulsory, "Should be compulsory");
        }


        [Test]
        public void Test_AllOwnerPropertiesAreCompulsory__WhenHasOneCompulsoryOwnerProp_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            FakeDMRelationship relationship = new FakeDMRelationship();
            var relationshipProperties = SetupRelationshipProperties(relationship);
            DMProperty ownerProperty = AddOwnerProperty(relationshipProperties, true);
            //---------------Assert Precondition----------------
            Assert.IsNotEmpty(relationship.RelationshipProperties);
            Assert.IsTrue(ownerProperty.Compulsory.GetValueOrDefault());
            //---------------Execute Test ----------------------
            bool compulsory = relationship.AllOwnerPropertiesAreCompulsory;
            //---------------Test Result -----------------------
            Assert.IsTrue(compulsory, "Should be compulsory");
        }
        [Test]
        public void Test_IsCompulsory_WhenAllOwnerPropsAreCompulsory_ShouldReturnTrue()
        {            
            //---------------Set up test pack-------------------
            FakeDMRelationship relationship = new FakeDMRelationship();
            relationship.SetOwningBOHasForeignKey(true);
            var relationshipProperties = SetupRelationshipProperties(relationship);
            AddOwnerProperty(relationshipProperties, true);
            AddOwnerProperty(relationshipProperties, true);
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationship.AllOwnerPropertiesAreCompulsory);
            Assert.IsTrue(relationship.OwningBOHasForeignKey);
            //---------------Execute Test ----------------------
            bool isCompulsory = relationship.IsCompulsory;
            //---------------Test Result -----------------------
            Assert.IsTrue(isCompulsory);
        }

        [Test]
        public void Test_IsCompulsory_WhenAllOwnerPropsNotCompulsory_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            FakeDMRelationship relationship = new FakeDMRelationship();
            var relationshipProperties = SetupRelationshipProperties(relationship);
            AddOwnerProperty(relationshipProperties, true);
            AddOwnerProperty(relationshipProperties, false);
            //---------------Assert Precondition----------------
            Assert.IsFalse(relationship.AllOwnerPropertiesAreCompulsory);
            //---------------Execute Test ----------------------
            bool isCompulsory = relationship.IsCompulsory;
            //---------------Test Result -----------------------
            Assert.IsFalse(isCompulsory);
        }

        [Test]
        public void Test_IsCompulsory_WhenOwningBOHasFKFalse_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            FakeDMRelationship relationship = new FakeDMRelationship();
            relationship.SetOwningBOHasForeignKey(false);
            var relationshipProperties = SetupRelationshipProperties(relationship);
            AddOwnerProperty(relationshipProperties, true);
            AddOwnerProperty(relationshipProperties, true);
            //---------------Assert Precondition----------------
            Assert.IsTrue(relationship.AllOwnerPropertiesAreCompulsory);
            Assert.IsFalse(relationship.OwningBOHasForeignKey);
            //---------------Execute Test ----------------------
            bool isCompulsory = relationship.IsCompulsory;
            //---------------Test Result -----------------------
            Assert.IsFalse(isCompulsory);
        }

        private DMRelationship CreatRelationship(DMClass ownerClass, DMClass relatedClass)
        {
            DMRelationship relationship = TestUtilsDMRelationship.CreateUnsavedDefaultDMRelationship();
            relationship.ClassDM = ownerClass;
            relationship.RelatedClass = relatedClass;
           return relationship;
        }

        private DMRelationship GetRelationshipWithOwnerClass(out DMClass dmClass)
        {
            DMRelationship relationship = new DMRelationship();
            dmClass = new DMClass();
            dmClass.Assembly = new DMAssembly();
            relationship.OwnerClass = dmClass;
            return relationship;
        }
        
        private DMRelationship GetStubDMRelationshipWithAKFalseAndPKFalse()
        {
            DMRelationship reverseRelationship;
            DMRelationship relationship = CreateStubWithReverseRelationship(out reverseRelationship);
            SetAllPKProps(reverseRelationship, false);
            SetAllAKProps(reverseRelationship, false);
            return relationship;
        }

        private DMRelationship GetStubDMRelationshipWithRRelPKTrue()
        {
            DMRelationship reverseRelationship;
            DMRelationship relationship = CreateStubWithReverseRelationship(out reverseRelationship);
            SetAllPKProps(reverseRelationship, true);
            SetAllAKProps(reverseRelationship, false);
            return relationship;
        }

        private static DMRelationship GetStubDMRelationshipWithRRelAKTrue()
        {
            DMRelationship reverseRelationship;
            DMRelationship relationship = CreateStubWithReverseRelationship(out reverseRelationship);
            SetAllPKProps(reverseRelationship, false);
            SetAllAKProps(reverseRelationship, true);
            return relationship;
        }

        private static DMRelationship CreateStubWithReverseRelationship(out DMRelationship reverseRelationship)
        {
            DMRelationship relationship = CreateStubDMRelationship();
            reverseRelationship = CreateStubDMRelationship();
            relationship.ReverseRelationship = reverseRelationship;
            return relationship;
        }

        private static DMRelationship CreateStubDMRelationship()
        {
            return MockRepository.GenerateStub<DMRelationship>(ConstructForFakes.True);
        }

        private static void SetAllPKProps(DMRelationship relationship, bool allPKProps)
        {
            relationship.Stub(rel => rel.HasAllPkProps()).Return(allPKProps);
        }
        private static void SetAllAKProps(DMRelationship relationship, bool allPKProps)
        {
            relationship.Stub(rel => rel.HasAllAkProps()).Return(allPKProps);
        }
        private static void AddTwoPropsToObjectID(DMClass ownerClass, DMObjectIdentity identity)
        {
            DMProperty dmProperty1 = TestUtilsDMProperty.CreateUnsavedValidDMProperty(ownerClass);
            DMProperty dmProperty2 = TestUtilsDMProperty.CreateUnsavedValidDMProperty(ownerClass);
            identity.Properties.Add(dmProperty1);
            identity.Properties.Add(dmProperty2);
        }

        private static void AddRelationshipProperty(DMRelationship dmRelationship, DMProperty property)
        {
            DMRelationshipProperty relationshipProperty1 = new DMRelationshipProperty {Property = property};
            dmRelationship.RelationshipProperties.Add(relationshipProperty1);
        }

        private static DMClass CreateClassWithAkAndRelationship()
        {
            DMProperty dmProperty = TestUtilsShared.CreateUnsavedValidDMProperty();
            DMClass dmClass = (DMClass) dmProperty.Class;
            DMRelationship dmRelationship = new DMRelationship();
            dmClass.OwnerRelationships.Add(dmRelationship);
            DMRelationshipProperty relationshipProperty = dmRelationship.RelationshipProperties.CreateBusinessObject();
            relationshipProperty.Property = dmProperty;
            DMUniqueConstraint uniqueConstraint = dmClass.UniqueConstraints.CreateBusinessObject();
            uniqueConstraint.AddPropertyInfo(dmProperty);
            return dmClass;
        }



        private static DMProperty AddOwnerProperty(FakeBusinessObjectCollection<DMRelationshipProperty> relationshipProperties, bool IsCompulsory)
        {
            var relationshipProperty = new FakeDMRelationshipProperty();
            var ownerProperty = MockRepository.GenerateStub<DMProperty>(ConstructForFakes.True);
            ownerProperty.Compulsory = IsCompulsory;
            relationshipProperty.OwnerProperty = ownerProperty;
            relationshipProperties.Add(relationshipProperty);
            return ownerProperty;
        }

        private FakeBusinessObjectCollection<DMRelationshipProperty> SetupRelationshipProperties(FakeDMRelationship relationship)
        {
            FakeBusinessObjectCollection<DMRelationshipProperty> relationshipProperties = new FakeBusinessObjectCollection<DMRelationshipProperty>();
            relationship.SetRelationshipProperties(relationshipProperties);
            return relationshipProperties;
        }
    }
}

